home *** CD-ROM | disk | FTP | other *** search
- /* access.c */
-
- #include <Files.h>
- #include <Aliases.h>
- #include <errno.h>
- #include "sys/unistd.h"
-
- #if defined(__MWERKS__) && (__MWERKS__ < 700)
- #define ioACUser filler2
- #endif
-
- int access( char *filename, int flags )
- {
- FSSpec fss;
- OSErr err;
- CInfoPBRec pb;
- Boolean isFolder, wasAliased;
- Str255 buf;
- long cur_dir;
- short cur_vol;
-
- c_to_p( filename, buf );
- HGetVol( NULL, &cur_vol, &cur_dir );
- // added to deal with aliases...
- err = FSMakeFSSpec( cur_vol, cur_dir, buf, &fss );
- if( err != noErr || ResolveAliasFile( &fss, 1, &isFolder, &wasAliased ) != noErr)
- return -1;
- pb.hFileInfo.ioCompletion = nil;
- pb.hFileInfo.ioVRefNum = fss.vRefNum; // was: cur_vol
- pb.hFileInfo.ioDirID = fss.parID; // was: cur_dir
- pb.hFileInfo.ioFDirIndex = 0;
- pb.hFileInfo.ioNamePtr = fss.name;
- if( PBGetCatInfoSync(&pb) != 0 ) { errno = ENOENT; return -1; }
- if( pb.dirInfo.ioFlAttrib & 0x10 )
- { // directory
- if( flags & W_OK != 0 )
- {
- if( pb.dirInfo.ioACUser & 0x04 ) /* locked */
- {
- errno = EIO;
- return -1;
- }
- }
- if( flags & X_OK != 0 )
- {
- if( pb.dirInfo.ioACUser & 0x01 ) /* no "see folders" priv */
- {
- errno = EIO;
- return -1;
- }
- }
- if( flags & R_OK != 0 ) { }
- {
- if( pb.dirInfo.ioACUser & 0x02 ) /* no "see files" priv */
- {
- errno = EIO;
- return -1;
- }
- }
- }
- else
- { // file
- if( flags & W_OK != 0 )
- {
- if( pb.hFileInfo.ioFlAttrib & 0x01 ) /* locked */
- {
- errno = EIO;
- return -1;
- }
- }
- if( flags & X_OK != 0 )
- {
- switch (pb.hFileInfo.ioFlFndrInfo.fdType)
- { case 'APPL':
- case 'BINA':
- break;
- default:
- errno = EIO;
- return -1;
- }
- }
- // if( flags & R_OK != 0 ) { }
- }
- return 0; /* All is well */
- }
-
- // end
-